package com.huobao.yunying.adapters;

import java.util.List;

import com.huobao.yunying.entity.FenleiChild;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Fenlei_GridView extends QuickAdapter<FenleiChild> {

	public Adapter_Fenlei_GridView(Context context, List<FenleiChild> data) {
		super(context, R.layout.item_fenlei_gridview, data);
	}


	@Override
	protected void convert(BaseAdapterHelper helper, FenleiChild data) {
		final ImageView imageView = helper.getView(R.id.imageview);
		TextView tv_name = helper.getView(R.id.tv_text);
		ImageUtils.loadimg(imageView, data.getLogo(), new OnImageLoadListener() {

			@Override
			public void onLoadSuccess(Drawable drawable) {
				int viewWidth = 0;
//				viewWidth = widht == 0 ? ScreenUtil.getInstant().getDisWidth(context) * 3 / 4 : widht;
				viewWidth = ScreenUtil.getInstant().getDisWidth(context) * 3 / 4;
				int newWidth = viewWidth / 3;
				int newHight = newWidth * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth();
				LayoutParams params = (LayoutParams) imageView.getLayoutParams();
				params.width = newWidth;
				params.height = newHight;
				imageView.setLayoutParams(params);
				imageView.setImageDrawable(drawable);
				notifyDataSetChanged();
			}
		});
		tv_name.setText(data.getValue());
	}

}
